package com.ebupt.migu.music.autoTri.Controller;

import com.ebupt.migu.music.autoTri.Service.VipPacketService;
import com.ebupt.migu.music.common.auth.IDAuthUtils;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @description: 会员红包模板管理
 * @author: liuyangyang@ebupt.com
 * @date: 2021/6/21 15:28
 */
@Slf4j
@RestController
@RequestMapping("/vip/packet")
public class VipPacketController {

    @Autowired
    private IDAuthUtils idAuthUtils;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private VipPacketService vipPacketService;

    /**
     * 创建红包模板
     *
     * @return
     */
    @PostMapping("/add")
    public ResultObject add() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        return vipPacketService.add(params);
    }

    /**
     * 查询红包模板
     *
     * @return
     */
    @PostMapping("/query")
    public ResultObject query() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        return vipPacketService.query(params);
    }

    /**
     * 删除红包模板
     *
     * @return
     */
    @PostMapping("/delete")
    public ResultObject delete() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        params = idAuthUtils.isAdmin(params);
        return vipPacketService.delete(params);
    }

    @PostMapping("/query/id")
    public ResultObject queryById() {
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        return vipPacketService.queryById(params);
    }
}
